package cjlu.ea.h.service.impl;

import cjlu.ea.h.entity.DBsyxwsqb;
import cjlu.ea.h.mapper.F102DBsyxwsqbMapper;
import cjlu.ea.h.service.F102DBsyxwsqbService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 学位申请汇总表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-09-03
 */
@Service
@Slf4j
public class F102DBsyxwsqbServiceImpl extends ServiceImpl<F102DBsyxwsqbMapper, DBsyxwsqb> implements F102DBsyxwsqbService {

    @Autowired
    F102DBsyxwsqbMapper f102DBsyxwsqbMapper;

    @Override
    public List<Object> getbyssj(DBsyxwsqb dBsyxwsqb, Long current, Long limit,String role) {
        QueryWrapper<DBsyxwsqb> wrapper = new QueryWrapper<>();

        //条件查询
        if(!StringUtils.isEmpty(dBsyxwsqb.getXh())){//学号
            wrapper.likeRight("xh",dBsyxwsqb.getXh());
        }
        if(dBsyxwsqb.getXm()!=null){//姓名
            wrapper.likeRight("xm",dBsyxwsqb.getXm());
        }
        if(dBsyxwsqb.getXy()!=null){//学院
            wrapper.likeRight("xy",dBsyxwsqb.getXy());
        }
        if(dBsyxwsqb.getBh()!=null){//班级
            wrapper.likeRight("bh",dBsyxwsqb.getBh());
        }
        if(dBsyxwsqb.getYy()!=null){//原因
            wrapper.eq("yy",dBsyxwsqb.getYy());
        }
        if(dBsyxwsqb.getCfsj()!=null){//惩罚时间
            wrapper.eq("cfsj",dBsyxwsqb.getCfsj());
        }
        if(dBsyxwsqb.getSqly()!=null){//申请理由
            wrapper.eq("sqly",dBsyxwsqb.getSqly());
        }
        if(dBsyxwsqb.getFhtk()!=null){//条款
            wrapper.eq("fhtk",dBsyxwsqb.getFhtk());
        }
        if(dBsyxwsqb.getShfs()!=null){//审核方式
            wrapper.eq("shfs",dBsyxwsqb.getShfs());
        }
        if(dBsyxwsqb.getShjg()!=null){//审核结果
            wrapper.eq("shjg",dBsyxwsqb.getShjg());
        }
        if(!StringUtils.isEmpty(role)){//权限控制
            wrapper.eq("xy",role);
        }

        //分页显示
        Page<DBsyxwsqb> page = new Page<>(current,limit);
        baseMapper.selectPage(page,wrapper);

        //数据查询获取
        List<DBsyxwsqb> list = page.getRecords();
        Long total = page.getTotal();
        List<Object> res = new ArrayList<>();
        res.add(list);
        res.add(total);
        log.info("ServiceImpl--F102 getbyssj(),查询特殊毕业生数据成功.....");
        return res;
    }

    @Override
    public void SaveOrUpdateByXh(List<DBsyxwsqb> list) {
        f102DBsyxwsqbMapper.savaOrUpdateBatchByXh(list);
        System.out.println("导入更新成功..");
    }
}
